<?php

namespace app\common\model\applymanager;

use think\Model;


class Apply extends Model
{

    

    

    // 表名
    protected $name = 'self_join_apply';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'address',
        'user_info',
        'gender_text',
        'status_text',
        'display_text'
    ];
    
    public function getAddressAttr($value, $data){
        $code = isset($data['county_id']) ? $data['county_id'] : (isset($data['city_id']) ? $data['city_id'] : (isset($data['province_id']) ? $data['province_id'] : 0));

        if($code){
            return \app\common\model\TxArea::getAddressByCode($code);
        }
        return null;
    }
    
    public function getGenderList()
    {
        return ['0' => __('Gender 0'), '1' => __('Gender 1')];
    }

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2')];
    }

    public function getDisplayList()
    {
        return ['0' => __('Display 0'), '1' => __('Display 1')];
    }


    public function getGenderTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['gender']) ? $data['gender'] : '');
        $list = $this->getGenderList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getDisplayTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['display']) ? $data['display'] : '');
        $list = $this->getDisplayList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getUserInfoAttr($value, $data){
        $value = isset($data['user_id']) ? $data['user_id'] : 0;
        return $value ? \app\common\model\User::getBaseInfoNosense($value) : '';
    }

}
